package com.li.spark0615.zhibiao

import org.apache.spark.sql.{SaveMode, SparkSession}
import org.apache.spark.sql.functions._

object Eight {
  def main(args: Array[String]): Unit = {

    System.setProperty("HADOOP_USER_NAME","root")

    val session = SparkSession
      .builder()
      .appName("li")
      .master("local[*]")
      .enableHiveSupport()
      .config("hive.metastore.uris", "thrift://192.168.23.40:9083")
      .config("dfs.client.use.datanode.hostname", "true")
      .config("hive.exec.dynamic.partition.mode", "nonstrict")
      .getOrCreate()

    session
      .table("ods.lx_com")
      .as("a")
      .join(
        session
          .table("ods.lx_com_click")
          .as("b")
        ,
        col("a.id") === col("b.id")
      )
      .orderBy(col("b.clicked") desc)
      .select("a.name","b.clicked")
      .limit(10)

      .write
      .format("jdbc")
      .option("url", "jdbc:mysql://192.168.23.40:3306/shtd_store?useSSL=false&characterEncoding=utf8")
      .option("user", "root")
      .option("password", "123456")
      .option("dbtable", "col_08")
      .mode(SaveMode.Overwrite)
      .save()


  }
}
